package weiyao.xinxidasai.Utils.FaceToken;

import com.baidu.aip.face.AipFace;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class FaceRegistry {

    public static final String APP_ID = FaceDetection.APP_ID;
    public static final String API_KEY = FaceDetection.API_KEY;
    public static final String SECRET_KEY = FaceDetection.SECRET_KEY;
    public static final String GROUP_ID = "3560_5440";

    public static boolean registerFace(String userId, String faceToken) {
        AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY);

        // 设置请求参数
        HashMap<String, String> options = new HashMap<>();
        options.put("action_type", "REPLACE");

        // 直接使用face_token注册
        JSONObject result = client.addUser(
                faceToken,        // 使用face_token作为图像参数
                "FACE_TOKEN",     // 指定类型为FACE_TOKEN
                GROUP_ID,
                userId,
                options
        );

        // 检查是否成功 (错误码0表示成功)
        boolean success = result.optInt("error_code", -1) == 0;
        System.out.println("人脸注册结果: " + success);
        return success;
    }
}